package com.digitalchina.lxnsy.activity.old;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessCollect;
import com.digitalchina.lxnsy.api.BusinessShareFarm;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.entity.ConsultVO;
import com.digitalchina.lxnsy.entity.EvaluateVO;
import com.digitalchina.lxnsy.entity.ShareFarmListVO;
import com.digitalchina.lxnsy.toolkit.CustomDialog;
import com.digitalchina.lxnsy.toolkit.FastJsonUtil;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.digitalchina.lxnsy.toolkit.Utils;
import com.facebook.drawee.view.SimpleDraweeView;
import com.hedgehog.ratingbar.RatingBar;

import java.util.Calendar;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2018/8/13 17:03
 * 修改备注：
 * ================================================
 */
public class ShareFarmDetailActivity extends BaseActivity {

    @Bind(R.id.sdv_image)
    SimpleDraweeView sdvImage;
    @Bind(R.id.tv_tips_gx)
    TextView tvTipsGx;
    @Bind(R.id.tv_tips_cs)
    TextView tvTipsCs;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_tips_gx_price)
    TextView tvTipsGxPrice;
    @Bind(R.id.tv_gx_price)
    TextView tvGxPrice;
    @Bind(R.id.tv_tips_bzj)
    TextView tvTipsBzj;
    @Bind(R.id.tv_bzj)
    TextView tvBzj;
    @Bind(R.id.tv_tips_bzjsm)
    TextView tvTipsBzjsm;
    @Bind(R.id.layout_gx)
    LinearLayout layoutGx;
    @Bind(R.id.layout_gmjg)
    LinearLayout layout_gmjg;
    @Bind(R.id. view_gmjg)
    View  view_gmjg;


    @Bind(R.id.tv_tips_gm_price)
    TextView tvTipsGmPrice;
    @Bind(R.id.tv_gm_price)
    TextView tvGmPrice;
    @Bind(R.id.tv_yunfei)
    TextView tvYunfei;
    @Bind(R.id.tv_ziti_address)
    TextView tvZitiAddress;
    @Bind(R.id.layout_ziti)
    LinearLayout layoutZiti;
    @Bind(R.id.tv_gxfw)
    TextView tvGxfw;
    @Bind(R.id.layout_gxfw)
    LinearLayout layoutGxfw;
    @Bind(R.id.layout_detail)
    RelativeLayout layoutDetail;
    @Bind(R.id.tv_tips1)
    TextView tvTips1;
    @Bind(R.id.tv_pingfen)
    TextView tvPingfen;
    @Bind(R.id.star_all_pingjia)
    RatingBar starAllPingjia;
    @Bind(R.id.view)
    View view;
    @Bind(R.id.rl_comment)
    RelativeLayout rlComment;
    @Bind(R.id.sdv_head)
    SimpleDraweeView sdvHead;
    @Bind(R.id.tv_comment_name)
    TextView tvCommentName;
    @Bind(R.id.tv_comment_time)
    TextView tvCommentTime;
    @Bind(R.id.star_user_pingjia)
    RatingBar starUserPingjia;
    @Bind(R.id.tv_comment_content)
    TextView tvCommentContent;
    @Bind(R.id.rl_zixun)
    RelativeLayout rlZixun;
    @Bind(R.id.tv_tips2)
    TextView tvTips2;
    @Bind(R.id.tv_tips3)
    TextView tvTips3;
    @Bind(R.id.scrollview)
    ScrollView scrollview;
    @Bind(R.id.tv_shop)
    TextView tvShop;
    @Bind(R.id.bt_buy)
    Button btBuy;
    @Bind(R.id.bt_lease)
    Button btLease;
    @Bind(R.id.tv_consult_nothing)
    TextView tvConsultNothing;
    @Bind(R.id.layout_consult)
    RelativeLayout layoutConsult;
    @Bind(R.id.rl_comment_user)
    RelativeLayout rlCommentUser;
    @Bind(R.id.tv_name_consult)
    TextView tvNameConsult;
    @Bind(R.id.tv_time_consult)
    TextView tvTimeConsult;
    @Bind(R.id.tv_consult)
    TextView tvConsult;
    @Bind(R.id.tv_name_reply)
    TextView tvNameReply;
    @Bind(R.id.tv_time_reply)
    TextView tvTimeReply;
    @Bind(R.id.tv_reply)
    TextView tvReply;
    @Bind(R.id.layout_show)
    LinearLayout layoutShow;
    @Bind(R.id.layout_out)
    LinearLayout layoutOut;
    @Bind(R.id.layout_new)
    LinearLayout layoutNew;
    @Bind(R.id.tv_sales)
    TextView tvSales;
    @Bind(R.id.tv_tel)
    TextView tvTel;
    @Bind(R.id.tv_lxr)
    TextView tvLxr;

    private ShareFarmListVO vo;
    Dialog dialog = null;

    int mYear;
    int mMonth;
    int mDayOfMonth;
    String mData = "";

    View dialogView1, dialogView2;
    //ShareFarmListVO.SubmitBean submitBean = new ShareFarmListVO.SubmitBean();

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_share_farm_detail);
        setTitle("共享详情");

        Drawable img = getResources().getDrawable(R.drawable.ic_v_collect);
        img.setBounds(0, 0, img.getMinimumWidth()/2, img.getMinimumHeight()/2);
        mTvRight.setCompoundDrawables(img, null, null, null);
        mTvRight.setText("收藏");
        mTvRight.setVisibility(View.VISIBLE);
    }

    @Override
    public void initMember() {

        Calendar calendar = Calendar.getInstance();
        mYear = calendar.get(Calendar.YEAR);
        mMonth = calendar.get(Calendar.MONTH);
        mDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        mData = mYear + "-" + (mMonth + 1) + "-" + mDayOfMonth;

        dialog = new Dialog(this, R.style.GoodsPropertyDialog);
        //获得dialog的window窗口
        Window window = dialog.getWindow();

        //设置dialog在屏幕底部
        window.setGravity(Gravity.BOTTOM);

        //设置dialog弹出时的动画效果，从屏幕底部向上弹出
        window.setWindowAnimations(R.style.Animation_Bottom_Dialog);
        window.getDecorView().setPadding(0, 0, 0, 0);

        //获得window窗口的属性
        WindowManager.LayoutParams lp = window.getAttributes();
        //设置窗口宽度为充满全屏
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        //设置窗口高度为包裹内容
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        //将设置好的属性set回去
        window.setAttributes(lp);


        String id = "";
        if (getIntent().hasExtra("ShareFarmListVO")) {
            vo = (ShareFarmListVO) getIntent().getSerializableExtra("ShareFarmListVO");
            id = vo.getId();
            setView();
        } else {
            id = (String) getIntent().getSerializableExtra("contentId");
        }
        BusinessShareFarm.getShareProductDetail(this, id, "", mHandler);
    }

    private void setView() {
        if (vo == null)
            return;

       /* if (0 == vo.getStatus()) { // 已下架
            layoutOut.setVisibility(View.VISIBLE);
        } else if (2 == vo.getStatus()) { // 查看最新商品
            layoutNew.setVisibility(View.VISIBLE);
        } else {
            layoutNew.setVisibility(View.GONE);
            layoutShow.setVisibility(View.VISIBLE);
        }*/

        FrescoUtil.showImageMid(vo.getImgPath(), sdvImage);

        if(vo.getShareType().size()!=2){
            if("共享".equals(vo.getShareType().get(0).name)){
                tvTipsGx.setVisibility(View.VISIBLE);
                tvTipsCs.setVisibility(View.GONE);


                tvGxPrice.setText(vo.getSharePrice()+ "元/"+vo.getUnit().name);

                tvSales.setText("共享数量："+vo.getProductNum());
                tvBzj.setText(vo.getEnsureMoney() + "元");
                layout_gmjg.setVisibility(View.GONE);
                view_gmjg.setVisibility(View.GONE);
            }else{
                tvTipsGx.setVisibility(View.GONE);
                tvTipsCs.setVisibility(View.VISIBLE);
                layoutGx.setVisibility(View.GONE);
                tvGmPrice.setText(vo.getSellPrice() + "元");
            }

        }else{

           tvGxPrice.setText(vo.getSharePrice()+ "元/"+vo.getUnit().name);

            tvSales.setText("共享数量："+vo.getProductNum());
            tvBzj.setText(vo.getEnsureMoney() + "元");
            tvGmPrice.setText(vo.getSellPrice() + "元");

        }
        tvTitle.setText(vo.getName() + "");




        //是否包邮 1 包邮 0 不包邮
        if ("1".equals(vo.getIsFreePostage())||vo.getIsFreePostage()==1)
            tvYunfei.setText("包邮");
        else
            tvYunfei.setText(vo.getPostage() + "元");

        // 自提 快递
        if ("1".equals(vo.getDeliveryMethod()))
            tvZitiAddress.setText("快递");
        else
            tvZitiAddress.setText("自提");

        tvGxfw.setText(vo.getPickUpAddress());

        tvTel.setText(vo.getContactNumber());
        tvLxr.setText(vo.getContactPeople());
    }

    @Override
    public void addListener() {

    }

    @Override
    public void setHandler() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what) {
                    case MSG.MSG_FIND_PRODUCT_EVALUTION_LIST_SUCCESS: // 评价
                        List<EvaluateVO> evaluateVOList = FastJsonUtil.getListBean(msg.obj.toString(), "productEvaList", EvaluateVO.class);
                        if (null == evaluateVOList || evaluateVOList.size() <= 0) { //无评论 则隐藏评论布局
                            rlCommentUser.setVisibility(View.GONE);
                        } else {
                            rlCommentUser.setVisibility(View.VISIBLE);
                            setItemEvaData(evaluateVOList);
                        }
                        break;
                    case MSG.MSG_FIND_PRODUCT_EVALUTION_LIST_FIELD:
                        rlCommentUser.setVisibility(View.GONE);
                        showToast(msg.obj.toString());
                        break;
                    case MSG.MSG_EVALUATION_TYPE_COUNT_SUCCESS: // 个评论个数和评分
                        String evaTypeCount = FastJsonUtil.getString(msg.obj.toString(), "productEvalateCounts");
                        if (!StringUtil.isStrEmpty(evaTypeCount)) {
                            String[] evaCountArray = new String[]{};
                            evaCountArray = evaTypeCount.split("\\|");
                            setEvaData(evaCountArray);
                        }
                        break;
                    case MSG.MSG_EVALUATION_TYPE_COUNT_FIELD:
                        tvTips1.setText(String.format("评价（%s）", "0"));
                        tvPingfen.setText(String.format("%s分", "0.0"));
                        starAllPingjia.setStar(0.0f);
//                        showToast(msg.obj.toString());
                        break;
                    case MSG.MSG_CONSULT_LIST_SUCCESS:
                        List<ConsultVO> consultVOList = FastJsonUtil.getListBean(msg.obj.toString(), "consultations", ConsultVO.class);

                        if (consultVOList != null && consultVOList.size() > 0) {
                            tvConsultNothing.setVisibility(View.GONE);
                            layoutConsult.setVisibility(View.VISIBLE);
                            tvConsult.setText(consultVOList.get(0).getConsultContent());

                            tvNameConsult.setText(consultVOList.get(0).getConsultMen().getMobilePhone());
                            tvNameReply.setText(consultVOList.get(0).getReplyMen().getMobilePhone());
                            tvTimeConsult.setText(consultVOList.get(0).getConsultTime());
                            tvTimeReply.setText(consultVOList.get(0).getReplyTime());

                            if (StringUtil.isStrEmpty(consultVOList.get(0).getReplyContent()))
                                tvReply.setText("等待回复");
                            else
                                tvReply.setText(consultVOList.get(0).getReplyContent());
                        } else {
                            tvConsultNothing.setVisibility(View.VISIBLE);
                            layoutConsult.setVisibility(View.GONE);
                        }
                        break;
                    case MSG.MSG_GET_SHARE_PRODUCT_DETAIL_SUCCESS: // 共享商品详情
                        vo = FastJsonUtil.getBeanData(msg.obj.toString(), ShareFarmListVO.class);
                        setView();
                        break;
                    case MSG.MSG_ADD_STORE_SUCCESS:
                        showToast("收藏成功");
                        break;
                    case MSG.MSG_ADD_STORE_FIELD:
                        showToast(msg.obj.toString());
                        break;
                    case MSG.MSG_GET_SHARE_PRODUCT_DETAIL_BY_NO_SUCCESS: // 快照
                        vo = FastJsonUtil.getBean(msg.obj.toString(), "product", ShareFarmListVO.class);
                        setView();
                        break;
                    case MSG.MSG_GET_SHARE_PRODUCT_DETAIL_BY_NO_FIELD:
                        showToast(msg.obj.toString());
                        break;
                }
            }
        };
    }

    /**
     * 设置总评价数据
     *
     * @param evaCount
     */
    private void setEvaData(String[] evaCount) {
        if (evaCount.length <= 0) {
            tvTips1.setText(String.format("评价（%s）", "0"));
            tvPingfen.setText(String.format("%s分", "0.0"));
            starAllPingjia.setStar(0.0f);
        } else {
            tvTips1.setText(String.format("评价（%s）", evaCount[1]));
            tvPingfen.setText(String.format("%s分", evaCount[0]));
            starAllPingjia.setStar(Float.parseFloat(evaCount[0]));
        }
    }

    /**
     * 设置第一条评论数据
     *
     * @param evaluateVOList 评论集合
     */
    private void setItemEvaData(List<EvaluateVO> evaluateVOList) {
        if (evaluateVOList.get(0).getImage() != null)
            FrescoUtil.showImageSmall(evaluateVOList.get(0).getImage(), sdvHead); // 评论者头像
        if (evaluateVOList.size() > 0) {
            if (evaluateVOList.get(0).isIsAnonymity()) // 匿名用户
                tvCommentName.setText("匿名用户");
            else
                tvCommentName.setText(evaluateVOList.get(0).getEvaluatePerson());
            tvCommentTime.setText(evaluateVOList.get(0).getEvaluateTime());
            tvCommentContent.setText(evaluateVOList.get(0).getContent());
            starUserPingjia.setStar(evaluateVOList.get(0).getScore());
        }
    }

    @Override
    public void callBack(Object object) {

    }

    @Override
    public void rightOnClick() {

        if (vo == null)
            return;
        if (noLoginToSkip()){
            BusinessCollect.addStore(ShareFarmDetailActivity.this, vo.getId(), "0", mHandler);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.tv_tips_bzjsm, R.id.layout_detail, R.id.rl_comment, R.id.rl_zixun, R.id.tv_shop, R.id.bt_buy, R.id.bt_lease})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_tips_bzjsm:
                CustomDialog.nativeDialog(ShareFarmDetailActivity.this, "保证金由卖家收取，租借前请先联系卖家完成保证金支付。");
                break;
            case R.id.layout_detail:
                if (vo != null)
                    GotoUtil.gotoActivity(ShareFarmDetailActivity.this, ShareFarmImageActivity.class, "ShareFarmListVO", vo);
                break;
            case R.id.rl_comment:
                GotoUtil.gotoActivity(ShareFarmDetailActivity.this, EvaluateListActivity.class, "productId", vo.getId());
                break;
            case R.id.rl_zixun:
                GotoUtil.gotoActivity(ShareFarmDetailActivity.this, ConsultListActivity.class, "ShareFarmListVO", vo);
                break;
            case R.id.tv_shop:
                GotoUtil.gotoActivity(ShareFarmDetailActivity.this, ShareShopActivity.class, "ShareFarmListVO", vo);
                break;
            case R.id.bt_buy:
                if (!Utils.isLogin(this)) {
                    Utils.notLoginGoto(this);
                    return;
                }
                if (vo != null)
                    showDialogBuy();
                break;
            case R.id.bt_lease:
                if (!Utils.isLogin(this)) {
                    Utils.notLoginGoto(this);
                    return;
                }
                if (vo != null)
                    showDialogLease();
                break;
        }
    }

    TextView tvDate;//租借时间选择
    String delivery1 = "";
    String delivery2 = "";

    // 租借
    private void showDialogLease() {


        if (dialogView2 == null) {
            dialogView2 = LayoutInflater.from(this).inflate(R.layout.dialog_zujie, null);
        }
        //将自定义布局加载到dialog上
        dialog.setContentView(dialogView2);

        ImageView ivCancelBtn = dialogView2.findViewById(R.id.iv_cancel);
        SimpleDraweeView sdv = dialogView2.findViewById(R.id.sdv_img);
        TextView tvPrice = dialogView2.findViewById(R.id.tv_price); // 租售价格
        TextView tvBzj = dialogView2.findViewById(R.id.tv_bzj); // 保证金
        final TextView tvPost = dialogView2.findViewById(R.id.tv_post); // 邮寄
        final TextView tvTake = dialogView2.findViewById(R.id.tv_take); // 自提
        TextView tvPostPrice = dialogView2.findViewById(R.id.tv_post_price); // 邮费
        tvDate = dialogView2.findViewById(R.id.tv_date); // 起租日期
        ImageView ivMinus = dialogView2.findViewById(R.id.iv_minus); // -
        ImageView ivPlus = dialogView2.findViewById(R.id.iv_plus); // +
        final TextView tvNum = dialogView2.findViewById(R.id.tv_num); // 购买数量
        ImageView ivMinus2 = dialogView2.findViewById(R.id.iv_minus2); // -
        ImageView ivPlus2 = dialogView2.findViewById(R.id.iv_plus2); // +
        final TextView tvNum2 = dialogView2.findViewById(R.id.tv_num2); // 单位个数
        Button btBuy = dialogView2.findViewById(R.id.bt_buy); // 租借按钮

        tvDate.setText(mData);

       /* if (vo.getProductImageList() != null && vo.getProductImageList().size() > 0)
            FrescoUtil.showImageMid(vo.getProductImageList().get(0).getImage(), sdv);
*/
        tvPrice.setText(tvGxPrice.getText().toString());
        tvBzj.setText(vo.getEnsureMoney() + "元");

        tvPostPrice.setText(tvYunfei.getText().toString());
       /* // 是否有邮寄方式
        if ("1".equals(vo.getHasPostMethod())) {
            tvPost.setVisibility(View.VISIBLE);
        } else
            tvPost.setVisibility(View.GONE);

        // 是否有自提方式
        if ("1".equals(vo.getHasTakenMethod())) {
            tvTake.setVisibility(View.VISIBLE);
        } else
            tvTake.setVisibility(View.GONE);
*/

        tvPost.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                delivery1 = "0";
                tvPost.setBackgroundResource(R.drawable.shape_app_color_solid_radius_12dp);
                tvTake.setBackgroundResource(R.drawable.shape_gray_solid_radius_12dp);
                tvPost.setTextColor(getResources().getColor(R.color.colorWhite));
                tvTake.setTextColor(getResources().getColor(R.color.colorFontBlack));
            }
        });

        tvTake.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                delivery1 = "1";
                tvTake.setBackgroundResource(R.drawable.shape_app_color_solid_radius_12dp);
                tvPost.setBackgroundResource(R.drawable.shape_gray_solid_radius_12dp);
                tvTake.setTextColor(getResources().getColor(R.color.colorWhite));
                tvPost.setTextColor(getResources().getColor(R.color.colorFontBlack));
            }
        });

        tvDate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDatePicker();
            }
        });

        ivMinus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int i = Integer.parseInt(tvNum.getText().toString());
                if (i > 1)
                    i--;
                tvNum.setText(i + "");
            }
        });
        ivPlus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int i = Integer.parseInt(tvNum.getText().toString());
                i++;
                tvNum.setText(i + "");
            }
        });

        ivMinus2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int i = Integer.parseInt(tvNum2.getText().toString());
                if (i > 1)
                    i--;
                tvNum2.setText(i + "");
            }
        });
        ivPlus2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int i = Integer.parseInt(tvNum2.getText().toString());
                i++;
                tvNum2.setText(i + "");
            }
        });
        ivCancelBtn.setOnClickListener(new View.OnClickListener() {// 取消
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        btBuy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!StringUtil.isStrEmpty(delivery1)) {
                    dialog.dismiss();
                  /*  // 0-租借 1-购买
                    submitBean.setType("0");
                    submitBean.setDate(tvDate.getText().toString());
                    // 交付方式 0-邮寄  1-自提
                    submitBean.setDelivery(delivery1);
                    submitBean.setNum1(tvNum.getText().toString());
                    submitBean.setNum2(tvNum2.getText().toString());

                    vo.setSubmit(submitBean);*/
                    GotoUtil.gotoActivity(ShareFarmDetailActivity.this, SubmitOrderShareActivity.class, "ShareFarmListVO", vo);
                } else
                    showToast("请选择交付方式");
            }
        });
        dialog.show();
    }

    // 购买

    private void showDialogBuy() {

        if (dialogView1 == null) {
            dialogView1 = LayoutInflater.from(this).inflate(R.layout.dialog_goumai, null);
        }
        //将自定义布局加载到dialog上
        dialog.setContentView(dialogView1);

        ImageView ivCancelBtn = dialogView1.findViewById(R.id.iv_cancel);
        SimpleDraweeView sdv = dialogView1.findViewById(R.id.sdv_img);
        TextView tvPrice = dialogView1.findViewById(R.id.tv_price); // 购买价格
        final TextView tvPost = dialogView1.findViewById(R.id.tv_post); // 邮寄
        final TextView tvTake = dialogView1.findViewById(R.id.tv_take); // 自提
        TextView tvPostPrice = dialogView1.findViewById(R.id.tv_post_price); // 邮费
        ImageView ivMinus = dialogView1.findViewById(R.id.iv_minus); // -
        ImageView ivPlus = dialogView1.findViewById(R.id.iv_plus); // +
        final TextView tvNum = dialogView1.findViewById(R.id.tv_num); // 购买数量
        Button btBuy = dialogView1.findViewById(R.id.bt_buy); // 购买按钮
/*

        if (vo.getProductImageList() != null && vo.getProductImageList().size() > 0)
            FrescoUtil.showImageMid(vo.getProductImageList().get(0).getImage(), sdv);
*/

        tvPrice.setText(tvGmPrice.getText().toString());

        tvPostPrice.setText(tvYunfei.getText().toString());
       /* // 是否有邮寄方式
        if ("1".equals(vo.getHasPostMethod())) {
            tvPost.setVisibility(View.VISIBLE);
        } else
            tvPost.setVisibility(View.GONE);

        // 是否有自提方式
        if ("1".equals(vo.getHasTakenMethod())) {
            tvTake.setVisibility(View.VISIBLE);
        } else
            tvTake.setVisibility(View.GONE);
*/

        tvPost.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                delivery2 = "0";
                tvPost.setBackgroundResource(R.drawable.shape_app_color_solid_radius_12dp);
                tvTake.setBackgroundResource(R.drawable.shape_gray_solid_radius_12dp);
                tvPost.setTextColor(getResources().getColor(R.color.colorWhite));
                tvTake.setTextColor(getResources().getColor(R.color.colorFontBlack));
            }
        });

        tvTake.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                delivery2 = "1";
                tvTake.setBackgroundResource(R.drawable.shape_app_color_solid_radius_12dp);
                tvPost.setBackgroundResource(R.drawable.shape_gray_solid_radius_12dp);
                tvTake.setTextColor(getResources().getColor(R.color.colorWhite));
                tvPost.setTextColor(getResources().getColor(R.color.colorFontBlack));
            }
        });


        ivMinus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int i = Integer.parseInt(tvNum.getText().toString());
                if (i > 1)
                    i--;
                tvNum.setText(i + "");
            }
        });
        ivPlus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int i = Integer.parseInt(tvNum.getText().toString());
                i++;
                tvNum.setText(i + "");
            }
        });

        ivCancelBtn.setOnClickListener(new View.OnClickListener() {// 取消
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        btBuy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!StringUtil.isStrEmpty(delivery2)) {
                    dialog.dismiss();
                   /* // 0-租借 1-购买
                    submitBean.setType("1");
                    // 交付方式 0-邮寄  1-自提
                    submitBean.setDelivery(delivery2);
                    submitBean.setNum1(tvNum.getText().toString());
                    submitBean.setNum2("1"); // 购买时 该数量不受影响

                    vo.setSubmit(submitBean);*/
                    GotoUtil.gotoActivity(ShareFarmDetailActivity.this, SubmitOrderShareActivity.class, "ShareFarmListVO", vo);
                } else
                    showToast("请选择交付方式");
            }
        });

        dialog.show();
    }

    /**
     * 显示日期选择
     */
    private void showDatePicker() {


        DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker datePicker, int year, int month, int dayOfMonth) {
                String date = year + "-" + (month + 1) + "-" + dayOfMonth;
                tvDate.setText(date);
            }
        }, mYear, mMonth, mDayOfMonth);

        datePickerDialog.show();
    }
}
